package bigDataSort;

import org.apache.hadoop.io.LongWritable;
import org.apache.hadoop.io.NullWritable;
import org.apache.hadoop.mapreduce.Reducer;

import java.io.IOException;

/**
 * 用于排序的Reducer
 */
public class BigDataReducer extends Reducer<LongWritable, NullWritable, LongWritable, LongWritable> {
    private LongWritable order = new LongWritable();

    private long curOrder = 0L;

    public void reduce(LongWritable key, Iterable<NullWritable> values,
                       Reducer<LongWritable, NullWritable, LongWritable, LongWritable>.Context context)
            throws IOException, InterruptedException {
        for (NullWritable value : values) {
            ++curOrder;
            order.set(curOrder);

            context.write(order, key);
        }
    }
}
